<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php $this->load->view('head'); ?>
</head>

<body>
	<?php $this->load->view('header_admin.php'); ?>
	
	<!-- Content Area -->
	<div class="wrapper-world content">
		<div class="wrapper">
		<?php if ($isEdit): ?>
		<h1><?php echo htmlspecialchars($uinfo->name); ?></h1>
		<?php else: ?>
		<h1>New user</h1>
		<?php endif; ?>
			
			<div class="left-half">
                            
                            <?php 
                            // display readonly part
                            if(isset($iscurrentuser) && !$iscurrentuser) {
                                ?>
                            <form class="standard-form" accept-charset="utf-8" method="post">
                                <div class="one">
                                        <label>Name</label>																		
                                        <div class="type-text">
                                            <span><?php echo $uinfo->name;?></span>
                                        </div>
                                        <div class="clr"></div>
                                </div>
                                <div class="one">
                                        <label>Email</label>																		
                                        <div class="type-text">
                                            <span><?php echo $uinfo->email;?></span>
                                        </div>
                                        <div class="clr"></div>
                                </div>                                
                                <div class="one">
                                        <label>Address</label>																		
                                        <div class="type-text">
                                            <span><?php echo $uinfo->address;?></span>
                                        </div>
                                        <div class="clr"></div>
                                </div>
                                <div class="one">
                                        <label>Phone</label>																		
                                        <div class="type-text">
                                            <span><?php echo $uinfo->phone;?></span>
                                        </div>
                                        <div class="clr"></div>
                                </div>
                                <div class="one">
                                        <label>User ID</label>																		
                                        <div class="type-text">
                                            <span><?php echo $uinfo->user_id;?></span>
                                        </div>
                                        <div class="clr"></div>
                                </div>
                                <div class="one">
                                        <label>Level</label>																		
                                        <div class="type-text">
                                            <span><?php 
                                            $levelData = array('User','Sales administrator','Operation administrator','Super user');
                                            echo $levelData[$uinfo->level];?></span>
                                        </div>
                                        <div class="clr"></div>
                                </div>
                                <div class="one">
                                        <label>Name</label>																		
                                        <div class="type-text">
                                            <span>
                                                <?php if(isset($uinfo->company->id)) {?>
                                                    <?php foreach ($companies as $company): ?>
                                                    <?php if($uinfo->company->id == $company->id) { echo $company->name;} ?>
                                                    <?php endforeach; ?>
                                                <?php } else { ?>
                                                    None
                                                <?php } ?>
                                            </span>
                                        </div>
                                        <div class="clr"></div>
                                </div>
                            </form>
                                <?php
                            } else {
                            ?>
                            
                            
				<?php echo form_open($formPost, array('class' => 'standard-form')); ?>
				
					<div class="one">
						<?php echo form_label('Name', 'name'); ?>
						<?php $nameInput = array('name' => 'name', 'id' => 'name'); ?>
						<?php
							if ($isEdit)
								$nameInput['value'] = $uinfo->name;
						?>
						<div class="type-text"><?php echo form_input($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('E-mail', 'email'); ?>
						<?php $nameInput = array('name' => 'email', 'id' => 'email'); ?>
						<?php
							if ($isEdit)
								$nameInput['value'] = $uinfo->email;
						?>
						<div class="type-text"><?php echo form_input($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('Password', 'password'); ?>
						<?php $nameInput = array('name' => 'password', 'id' => 'password'); ?>
						<div class="type-text"><?php echo form_password($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('Password (2)', 'confirmpassword'); ?>
						<?php $nameInput = array('name' => 'confirmpassword', 'id' => 'confirmpassword'); ?>
						<div class="type-text"><?php echo form_password($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('Address', 'address'); ?>
						<?php $nameInput = array('name' => 'address', 'id' => 'address'); ?>
						<?php
							if ($isEdit)
								$nameInput['value'] = $uinfo->address;
						?>
						<div class="type-text"><?php echo form_input($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('Phone', 'phone'); ?>
						<?php $nameInput = array('name' => 'phone', 'id' => 'phone'); ?>
						<?php
							if ($isEdit)
								$nameInput['value'] = $uinfo->phone;
						?>
						<div class="type-text"><?php echo form_input($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('User ID', 'user_id'); ?>
						<?php $nameInput = array('name' => 'user_id', 'id' => 'user_id'); ?>
						<?php
							if ($isEdit)
								$nameInput['value'] = $uinfo->user_id;
						?>
						<div class="type-text"><?php echo form_input($nameInput); ?></div>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('Level', 'level'); ?> 
						<select name="level" id="level">
							<option value="0"<?php if ($isEdit) { if ($uinfo->level == 0) { ?> selected<?php } }?>>User</option>
							<option value="1"<?php if ($isEdit) { if ($uinfo->level == 1) { ?> selected<?php } }?>>Sales administrator</option>
							<option value="2"<?php if ($isEdit) { if ($uinfo->level == 2) { ?> selected<?php } }?>>Operation administrator</option>
							<option value="3"<?php if ($isEdit) { if ($uinfo->level == 3) { ?> selected<?php } }?>>Super user</option>
						</select>
						<div class="clr"></div>
					</div>
					<div class="one">
						<?php echo form_label('Company', 'company'); ?>
						<select name="company" id="company">
							<option value="0">None</option>
							<?php foreach ($companies as $company): ?>
							<option value="<?php echo $company->id; ?>"<?php if ($isEdit) { if (isset($uinfo->company->id) && $uinfo->company->id == $company->id) { ?> selected<?php } }?>><?php echo $company->name; ?></option>
							<?php endforeach; ?>
						</select>
						<div class="clr"></div>
					</div>
					
					<div class="one no-left">
						<div class="type-btn"><?php echo form_submit('doedit', 'Submit'); ?></div>
						<div class="clr"></div>
					</div>
				</form>
                                <?php } ?>
			</div>
			
			<div class="clr"></div>
		</div>
		
		<!--          -----------------------------------------------------------------------------          -->
		
	</div></div>	<!-- end of wrapper-world and .content -->
	
	
		
	<div class="wrapper-world footer-top">
		<div class="wrapper"></div>	
	</div>
	
	<?php $this->load->view('footer'); ?>
</body>
</html>
